<script>
	import { userApi } from '@/common/api/index.js';
	import { mapMutations } from 'vuex';
	export default {
		onLaunch: function() {
			this.initApp()
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		},
		methods: {
			...mapMutations('user', ['setOpenId']),
			initApp() { // 初始化
				try {
					uni.login({
						provider: "weixin",
						success: async (loginRes) => {
							const res = await userApi.getOpenId({
								Code: loginRes.code,
								App_ID: uni.getAccountInfoSync().miniProgram.appId
							})
							this.setOpenId(res?.openid);
						},
					})
				} catch (error) {
					console.error('应用初始化失败', error)
					this.$utils.showToast('初始化失败，请重试');
				}
			}
		}
	}
</script>

<style>
	/*每个页面公共css */
	@import "static/css/free.css";
</style>